package com.orientsec.autotest.project.system.systemSqlconn.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.orientsec.autotest.framework.aspectj.lang.annotation.Log;
import com.orientsec.autotest.framework.aspectj.lang.enums.BusinessType;
import com.orientsec.autotest.project.system.systemSqlconn.domain.SystemSqlconn;
import com.orientsec.autotest.project.system.systemSqlconn.service.ISystemSqlconnService;
import com.orientsec.autotest.framework.web.controller.BaseController;
import com.orientsec.autotest.framework.web.page.TableDataInfo;
import com.orientsec.autotest.framework.web.domain.AjaxResult;
import com.orientsec.autotest.common.utils.poi.ExcelUtil;

/**
 * sql连接字符串信息操作处理
 * 
 * @author autotest
 * @date 2019-12-18
 */
@Controller
@RequestMapping("/system/systemSqlconn")
public class SystemSqlconnController extends BaseController
{
    private String prefix = "system/systemSqlconn";
	
	@Autowired
	private ISystemSqlconnService systemSqlconnService;
	
	@RequiresPermissions("system:systemSqlconn:view")
	@GetMapping()
	public String systemSqlconn()
	{
	    return prefix + "/systemSqlconn";
	}
	
	/**
	 * 查询sql连接字符串列表
	 */
	@RequiresPermissions("system:systemSqlconn:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SystemSqlconn systemSqlconn)
	{
		startPage();
        List<SystemSqlconn> list = systemSqlconnService.selectSystemSqlconnList(systemSqlconn);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出sql连接字符串列表
	 */
	@RequiresPermissions("system:systemSqlconn:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SystemSqlconn systemSqlconn)
    {
    	List<SystemSqlconn> list = systemSqlconnService.selectSystemSqlconnList(systemSqlconn);
        ExcelUtil<SystemSqlconn> util = new ExcelUtil<SystemSqlconn>(SystemSqlconn.class);
        return util.exportExcel(list, "systemSqlconn");
    }
	
	/**
	 * 新增sql连接字符串
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存sql连接字符串
	 */
	@RequiresPermissions("system:systemSqlconn:add")
	@Log(title = "sql连接字符串", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SystemSqlconn systemSqlconn)
	{		
		return toAjax(systemSqlconnService.insertSystemSqlconn(systemSqlconn));
	}

	/**
	 * 修改sql连接字符串
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		SystemSqlconn systemSqlconn = systemSqlconnService.selectSystemSqlconnById(id);
		mmap.put("systemSqlconn", systemSqlconn);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存sql连接字符串
	 */
	@RequiresPermissions("system:systemSqlconn:edit")
	@Log(title = "sql连接字符串", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SystemSqlconn systemSqlconn)
	{		
		return toAjax(systemSqlconnService.updateSystemSqlconn(systemSqlconn));
	}
	
	/**
	 * 删除sql连接字符串
	 */
	@RequiresPermissions("system:systemSqlconn:remove")
	@Log(title = "sql连接字符串", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(systemSqlconnService.deleteSystemSqlconnByIds(ids));
	}
	
}
